﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace InterValometer
{
    class Session
    {
        public Acquisition Acquisition;
        public Location Location;
        public Target Target;
        public Sequence Sequence;

        /// <summary>
        /// Create a new blank Session
        /// </summary>
        public Session()
        {
            // This is a new session, allocate blank data structures
            Acquisition = new Acquisition();
            Location = new Location();
            Target = new Target();
            Sequence = new Sequence();

            // We don't exist in the DB yet
            UID = -1;
        }

        /// <summary>
        /// Retrieve and existing Session from the database
        /// </summary>
        /// <param name="ses_uid"></param>
        public Session(int ses_uid) : this()
        {
            // This is an existing session, allocate blank data structures
            // and populate from database
            this.UID = ses_uid;
        }

        /// <summary>
        /// Write all outstanding changes to database.
        /// </summary>
        /// <returns></returns>
        public bool Commit()
        {
            bool status = true;

            // If we're a new session, perform INSERT
            if (UID == -1)
            {
                // if INSERT is not successful then status = false
            }
            // We already exist, perform UPDATE
            else
            {
                // if UPDATE is not successful then status = false

                // Acquisition.Commit(db_connection)
                // Location.Commit(db_connection)
                // Target.Commit(db_connection)
                // Sequence.Commit(db_connection)
            }

            return status;
        }

        public int UID { get; set; }
    }
}
